<?php
//占位
class class_sess implements SessionHandlerInterface
{
	var $key = 'PHPSESSION';
//---------------------------------------------------------------------------------
	protected function id($id)
	{
		return "{$this->key}_{$id}";
	}
//---------------------------------------------------------------------------------
	function ids()
	{
		$ids = [];
		$keys = [];
		$array = rdb_array_get($this->key);
		if(is_array($array))
		{
			foreach($array as $k => $v)
			{
				$key = $this->id($v);
				$str = rdb_get($key);
				preg_match('~UID\|i:([\d]+);~', $str, $match);
				if($match[1])
				{
					$ids[$k] = $match[1];
					$keys[$k] = $v;
				}
			}
		}
		
		return [$ids,$keys];
	}
//---------------------------------------------------------------------------------
	protected function sessid_has($id)
	{
		return rdb_array_has($this->key, $id);
	}
//---------------------------------------------------------------------------------
	protected function sessid_add($id)
	{
		if(!$this->sessid_has($id))
			rdb_array_setone($this->key, $id);
	}
//---------------------------------------------------------------------------------
	protected function sessid_del($id)
	{
		if($this->sessid_has($id))
			rdb_array_delone($this->key, $id);
	}
//---------------------------------------------------------------------------------
	function settime()
	{
		
	}
//---------------------------------------------------------------------------------
	function gettime($session_id)
	{
		$id = $this->id($session_id);
		return rdb_ttl($id);
	}
//---------------------------------------------------------------------------------

	function open($save_path, $name)
	{
		return true;
	}
//---------------------------------------------------------------------------------
	function read($session_id)
	{
		//_log1("read:{$session_id}");
		
		$id = $this->id($session_id);
		$str = rdb_get($id);
		
		if($str === false)
		{
			$this->sessid_del($session_id);
			return '';
		}
		else
		{
			$this->sessid_add($session_id);
			return $str;
		}
	}
//---------------------------------------------------------------------------------
	function write($session_id, $session_data)
	{
		//_log1("write:{$session_id}");
		
		$id = $this->id($session_id);
		rdb_set($id, $session_data, $GLOBALS['SESS_TIME'] ? $GLOBALS['SESS_TIME'] : 3600);
		$this->sessid_add($session_id);
		return true;
	}
//---------------------------------------------------------------------------------
	function close()
	{
		return true;
	}
//---------------------------------------------------------------------------------
	function destroy($session_id)
	{
		//_log1("destroy:{$session_id}");
		
		$id = $this->id($session_id);
		rdb_del($id);
		$this->sessid_del($session_id);
		return true;
	}
//---------------------------------------------------------------------------------
	function gc($maxlifetime)
	{
		return true;
	}
//---------------------------------------------------------------------------------
	function create_sid()
	{
		return _only();
	}
}